# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=jbig2dec
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.19
pkgrel=1
pkgdesc='Decoder implementation of the JBIG2 image compression format (mingw-w64)'
url='https://jbig2dec.com/'
arch=('any')
license=('AGPL')
depends=("${MINGW_PACKAGE_PREFIX}-libpng")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/ArtifexSoftware/jbig2dec/archive/${pkgver}.tar.gz
        01-dont-run-configure-from-autogen.patch
        02-mingw-no-inlines.patch)
sha256sums=('e81b787ad0b147a437a52d9ce7de1a8f429655e8aa030383b6b2dd8919373717'
            '8715e0b3dfd738f9db57c656859897a41bc43d308ba86318ced625736784b54b'
            '18731257e8bddcf76663c0734ba3711b2e5c7c13f0841b6833ec17f90aa23186')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/01-dont-run-configure-from-autogen.patch
  patch -p1 -i ${srcdir}/02-mingw-no-inlines.patch
  ./autogen.sh
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  #cp -r ${_realname}-${pkgver} "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  export lt_cv_deplibs_check_method='pass_all'
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --build=${MINGW_CHOST} \
      --enable-shared \
      --enable-static

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
